# Contributor: Sören Tempel <soeren+alpine@soeren-tempel.net>
# Maintainer: Sören Tempel <soeren+alpine@soeren-tempel.net>
pkgname=booster
pkgver=0.11
pkgrel=4
pkgdesc="Fast and secure initramfs generator"
url="https://github.com/anatol/booster"
arch="all"
license="MIT"
makedepends="go ronn"
# kbd: needed for vconsole feature
depends="kbd"
options="net !check" # TODO: enable check
subpackages="$pkgname-doc"
triggers="$pkgname.trigger=/usr/share/kernel/*"
source="https://github.com/anatol/booster/archive/refs/tags/$pkgver/booster-$pkgver.tar.gz
	support-converted-luks-volumes.patch
	README.alpine
	booster.yaml"

provides="initramfs-generator"
provider_priority=1 # lowest, **must** be lower than main/mkinitfs

export GOFLAGS="$GOFLAGS -trimpath -modcacherw"
export GOCACHE="${GOCACHE:-"$srcdir/go-cache"}"
export GOTMPDIR="${GOTMPDIR:-"$srcdir"}"
export GOMODCACHE="${GOMODCACHE:-"$srcdir/go"}"

prepare() {
	go mod vendor
	default_prepare
}

build() {
	cd "$builddir"/generator
	go build --ldflags="-X main.imageModulesDir=/lib/modules/ \
		-X main.firmwareDir=/lib/firmware/ \
		-X main.consolefontsDir=/usr/share/consolefonts/"

	# Build the init itself without CGO and in default buildmode.
	# Otherwise, we always need musl in the ramdisk.
	cd "$builddir"/init
	CGO_ENABLED=0 go build -buildmode=default

	cd "$builddir"/docs
	ronn manpage.md
}

package() {
	install -Dm644 "$srcdir"/booster.yaml "$pkgdir"/etc/booster.yaml
	install -Dm644 "$srcdir"/README.alpine "$pkgdir"/usr/share/doc/$pkgname/README.alpine
	install -Dm644 docs/manpage.1 "$pkgdir"/usr/share/man/man1/booster.1

	install -Dm755 generator/generator "$pkgdir"/usr/bin/booster
	install -Dm755 init/init "$pkgdir"/usr/lib/booster/init
}

sha512sums="
fbccb75b57d38696d4e81f0c587c6c456270290d4867b1e5028363beff9f0b08770719e0fcc991bd6c751fe48fdd8d2aee262355b8691caeb6ee702d6cccb7a0  booster-0.11.tar.gz
f1377a0f3aa61f4dea138bec8dc9baf9b3e48a8cbca9c2143dfbe7d78770d8355d4ad6dbb2a87edb4ea44c1e6f1d8f68ab7ad42ca55d8c960921c0020c632dad  support-converted-luks-volumes.patch
15737769d83f1590efc5ef4775a5a8efb42d845a41ab3eac9a67f0ea89edfc3936e589cfc1042d4df054d812e5e54e9777fe9a7b6c5b2c5b40b2dde7ae7986d1  README.alpine
a3e68264c41e06d68d255ec6d5ed918f837225cbd65b3850212b06aa2c2a7ba33bf022576561a3813f80e5031a3e1e3a9aa42945a4342c998e31f1089dea5687  booster.yaml
"
